home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
turbovis
/
scrsav4.zip
/
SCRSAV.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1994-04-10
|
22KB
|
642 lines
{
SCRSAV.PAS - A ScreenSaving unit (version 4) for TurboVision 2.0
This ScreenSaving-unit for TurboVision 2.0 is (c) by Edwin Groothuis
You are allowed to use this unit in your programs if you agree to
these two rules:
1. You give me proper credit in the documentation of the program.
2. You tell me you're using this unit.
If you don't agree with these two rules, you're not allowed to
use it!
How to use this ScreenSaving-unit:
Initialisation:
- Add the ScrSav-unit to the uses-command.
- Make the (global) variable ScreenSaver as PScreenSaver
- In the Initialisation of an Application, put the following
line behind the Inherited Init:
Inherited Init;
ScreenSaver:=New(PScreenSaver,Init(MakeStandardScreenSaver,6));
Heartbeat:
To tell the ScreenSaver that the user isn't idle at this moment,
put the following line in the Application^.GetEvent:
Inherited GetEvent(E);
if E.What<>evNothing then
if ScreenSaver<>nil then
if E.What=evKeyDown then
begin
if ScreenSaver^.Saving then
E.What:=evNothing;
ScreenSaver^.HeartBeat;
end else
if E.What and evMouse<>0 then
ScreenSaver^.HeartBeat;
CountDown:
To let the ScreenSaver know the user is idle at this moment, put
the following line in the Application^.Idle:
Inherited Idle;
if ScreenSaver<>nil then
ScreenSaver^.CountDown;
Options:
What is a ScreenSaver without options? You can change the
options by calling the ScreenSaver^.Options-procedure. The user
gets a nice options-dialog and he can change some settings. If
you have added more ScreenSaver-modules, please add them in the
constants ScreenSaverNames and ScreenSaverProcs. Make sure you
put them in alphabetic order!
Now start your application. After 6 seconds your screen will
go blank. There are several ScreenSavers designed by me, if
you have created more, I would like to have a copy of them ;-)
A small note about the use of a delay in the ScreenSaver^.Update:
It's not nice to use the Delay-function of the Crt-unit. Instead
of using that, you'd better check if a certain time (100 ms, 200 ms
and so on) has elapsed. See the StarFieldScreenSaver.Update-function
for an example of it.
Send all your suggestions/money/cards (I love to get cards from
people who are using my programs) to:
Edwin Groothuis ECA-BBS
Johann Strausslaan 1 tel. +31-40-550352 (up to 14k4/V42b)
5583ZA Aalst-Waalre FTN: 2:284/205@fidonet
The Netherlands 115:3145/102@pascal-net
request SCRSAV for the last version!
}
unit ScrSav;
interface
uses Views,Objects;
type PScreenSaver=^TScreenSaver;
TScreenSaver=object
constructor Init(_W:PView;Time:word);
destructor Done;
procedure Activate;
procedure Deactivate;
procedure HeartBeat;
procedure CountDown;
procedure Update;virtual;
function Saving:boolean;
procedure Options;
procedure Enable(b:boolean);
private
W:PView;
LastBeat:longint;
_Saving:boolean;
SavedScreen:pointer;
SavingTime:word;
CursorVisible:boolean;
Enabled:boolean;
Testing:boolean;
end;
type PStandardScreenSaver=^TStandardScreenSaver;
TStandardScreenSaver=object(TView)
constructor Init;
procedure Draw;virtual;
end;
function MakeStandardScreenSaver :PStandardScreenSaver;
function MakeMovingStarScreenSaver:PStandardScreenSaver;
function MakeWormScreenSaver :PStandardScreenSaver;
function MakeStarFieldScreenSaver :PStandardScreenSaver;
implementation
uses Drivers,App,Dialogs,InpLong;
const NumScreenSavers=4;
const ScreenSaverNames:array[0..NumScreenSavers-1] of string[20]=
(
'Moving Star',
'Standard',
'Starfield',
'Worm'
);
ScreenSaverProcs:array[0..NumScreenSavers-1] of function:
PStandardScreenSaver=(
MakeMovingStarScreenSaver,
MakeStandardScreenSaver,
MakeStarfieldScreenSaver,
MakeWormScreenSaver
);
const cmTest=1000;
{----------------------------------------------------------------------------}
{ Object-definitions of the screensave-routines. Note that these are not the
screensaverobject! }
type PMovingStarScreenSaver=^TMovingStarScreenSaver;
TMovingStarScreenSaver=object(TStandardScreenSaver)
constructor Init;
procedure Draw;virtual;
private
dx,dy,x,y:array[1..10] of integer;
LastUpdate:longint;
end;
PWormScreenSaver=^TWormScreenSaver;
TWormScreenSaver=object(TStandardScreenSaver)
constructor Init;
procedure Draw;virtual;
private
x,y:array[1..10] of integer;
states:array[1..10] of char;
dx,dy:integer;
LastUpdate:longint;
end;
PStarFieldScreenSaver=^TStarFieldScreenSaver;
TStarFieldScreenSaver=object(TStandardScreenSaver)
constructor Init;
procedure Draw;virtual;
private
states:array[1..7] of char;
starstate,x,y:array[1..10] of integer;
LastUpdate:longint;
end;
{----------------------------------------------------------------------------}
{ Object-definition of the screensaver }
type PScrSavDialog=^TScrSavDialog;
TScrSavDialog=object(TDialog)
UserSavingTime:PInputLine;
LB:PListBox;
TestButton:PButton;
Timer:PRadioButtons;
procedure HandleEvent(var E:TEvent);virtual;
end;
var CurrentScreenSaver:PScreenSaver;
{----------------------------------------------------------------------------}
{----------------------------------------------------------------------------}
{ Initialise the ScreenSaver.
Notes:
*18.2 is because the timertick goes 18.2 times/second }
constructor TScreenSaver.Init(_W:PView;Time:word);
begin
_Saving:=fals